#include "stdafx.h"
#include "PathUtil.h"

USING_NS_UTILS

std::string PathUtil::exeDir()
{
	char path[MAX_PATH ] = { 0 };
	GetModuleFileNameA(NULL, path, MAX_PATH);
	(strrchr(path, '\\'))[1] = 0;
	return path;
}

std::string PathUtil::tmpDir()
{
	char path[MAX_PATH] = { 0 };
	GetTempPathA(MAX_PATH, path);
	return path;
}

std::string PathUtil::getFileName(const std::string& path)
{
	size_t pos = path.find_last_of("/\\");
	return path.substr(pos + 1, path.length() - pos - 1);
}

std::string PathUtil::getFileExtension(const std::string& path)
{
	std::string filename = getFileName(path);
	return filename.substr(filename.find_last_of('.') + 1);
}

std::string PathUtil::getFileNameWithoutExtension(const std::string& path)
{
	std::string filename = getFileName(path);
	return filename.substr(0, filename.rfind('.'));;
}

std::string PathUtil::getDirectoryName(const std::string& path)
{
	size_t pos = path.find_last_of("/\\");
	return path.substr(0, pos + 1);
}

std::string PathUtil::getRootName(const std::string& path)
{
	size_t pos = path.find_first_of(':');
	return path.substr(0, pos + 1);
}

